package org.summer.generator;

import org.summer.generator.log.Logger;
import org.summer.generator.log.LoggerManager;
import org.summer.generator.resolver.ConfigResolver;

public class DefaultGenerator implements Generator{
    private static final Logger log = LoggerManager.getLogger(DefaultGenerator.class);
    private FileCreateDelegate fileCreateDelegate;
    private DefaultGenerator(){}
    public static DefaultGenerator getInstance(){
        return new DefaultGenerator();
    }
    @Override
    public Generator init() {
        log.debug("代码生成器初始化");
        ConfigResolver configParse = new ConfigResolver();
        configParse.resolver();
        this.fileCreateDelegate =
                new FileCreateDelegate(
                        configParse.resolverDatabaseConfig(),
                        configParse.resolverProjectConfig(),
                        configParse.resolverCreateConfig(),
                        configParse.resolverWriterConfig());
        return this;
    }

    @Override
    public Generator create(String tableName) {
        log.debug("根据数据表明生成各层代码： " + tableName);
        this.fileCreateDelegate.writerCodeToFile(tableName);
        return this;
    }
}
